package com.diligreat.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.diligreat.domain.Content;
import com.diligreat.domain.Lang;
import com.diligreat.domain.Selection;
import com.diligreat.mapper.ContentMapper;
import com.diligreat.mapper.LangMapper;
import com.diligreat.mapper.LangmodelMapper;
import com.diligreat.mapper.SelectionMapper;

@Service
public class StartUpService {

	
	@Autowired
	private ContentMapper cm;
	
	@Autowired
	private LangMapper lm;
	
	@Autowired
	private SelectionMapper sm;
	
	@Autowired
	private LangmodelMapper lmm;
	
	/**
	 * 获得4组TITLE的LIST
	 * @param lang
	 * @return
	 */
	public List<Content> getConsultationTitleList(long lang)
	{
		Content c=new Content();
		c.setLangId(lang);
		c.setUnderId(1);
		c.setIsTitle(0);
		return this.cm.getTitleByParameters(c);
	}
	
	public List<Content> getTechTitleList(long lang)
	{
		Content c=new Content();
		c.setLangId(lang);
		c.setUnderId(2);
		c.setIsTitle(0);
		return this.cm.getTitleByParameters(c);
	}
	
	public List<Content> getArrangementTitleList(long lang)
	{
		Content c=new Content();
		c.setLangId(lang);
		c.setUnderId(3);
		c.setIsTitle(0);
		return this.cm.getTitleByParameters(c);
	}
	
	public List<Content> getIndustryTitleList(long lang)
	{
		Content c=new Content();
		c.setLangId(lang);
		c.setUnderId(4);
		c.setIsTitle(0);
		return this.cm.getTitleByParameters(c);
	}
	
	
	
	/**
	 * 获取区域资源, 用在启动服务中, 获取区域语言选择的列表
	 * @return
	 */
	public List<Lang> getLangResource()
	{
		List<Lang> l=this.lm.getLangGroupById(0);
		
		for(int i=0;i<l.size();i++)
		{
			Lang tmp=(Lang)l.get(i);
			
			List<Lang> ls=this.lm.getLangGroupById(tmp.getId());
			/**
			for(int j=0;j<ls.size();j++)
			{
				Lang tmpsec=(Lang)ls.get(j);
				
				
				tmpsec.setConsultatinglist(this.getConsultationTitleList(tmpsec.getId()));
				tmpsec.setTechlist(this.getTechTitleList(tmpsec.getId()));
				tmpsec.setArrangementlist(this.getArrangementTitleList(tmpsec.getId()));
				tmpsec.setIndustrylist(this.getIndustryTitleList(tmpsec.getId()));
				
				tmpsec.setTop(this.cm.getLabelTopContentByLang(tmpsec.getId()));
				tmpsec.setBottom(this.cm.getLabelBotContentByLang(tmpsec.getId()));
			}
			*/
			tmp.setUnderlist(ls);
			
		}
		
		return l;
	}
	
	/**
	 * 获得初始化的列表
	 * @return
	 */
	public HashMap<String, Lang> getSecStepLang()
	{
		HashMap<String, Lang> hs=new HashMap<String, Lang>();
		
		List<Lang> l=this.lm.getLangSecStepGroup();
		
		for(int j=0;j<l.size();j++)
		{
			Lang tmpsec=(Lang)l.get(j);
			
			
			tmpsec.setConsultatinglist(this.getConsultationTitleList(tmpsec.getId()));
			tmpsec.setTechlist(this.getTechTitleList(tmpsec.getId()));
			tmpsec.setArrangementlist(this.getArrangementTitleList(tmpsec.getId()));
			tmpsec.setIndustrylist(this.getIndustryTitleList(tmpsec.getId()));
			
			tmpsec.setTop(this.cm.getLabelTopContentByLang(tmpsec.getId()));
			tmpsec.setBottom(this.cm.getLabelBotContentByLang(tmpsec.getId()));
			tmpsec.setMorecontact(this.cm.getLabelOnlyContentByLang(tmpsec.getId()));
			
			
			Selection s=new Selection();
			s.setLang(tmpsec.getId());
			
			s.setCataid(2);
			tmpsec.setFlist(sm.getSelection(s));
			
			
			s.setCataid(3);
			tmpsec.setClist(sm.getSelection(s));
			
			s.setCataid(5);
			tmpsec.setPlist(sm.getSelection(s));
			
			
			tmpsec.setLangmodel(this.lmm.getLangmodelById(tmpsec.getId()));
			
			
			hs.put((new Long(tmpsec.getId())).toString(),tmpsec);
		}
		
		
		return hs;
	}
}
